home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / Storage.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  10.8 KB  |  391 lines

  1. package
  2. {
  3.    import Common.*;
  4.    import flash.display.*;
  5.    import flash.events.Event;
  6.    import flash.events.FullScreenEvent;
  7.    import flash.media.SoundTransform;
  8.    import flash.net.*;
  9.    import flash.utils.*;
  10.    
  11.    public class Storage
  12.    {
  13.       
  14.       internal static const OPTIONSKEY:String = "GameServicesGroup/CluelessDemo/0.4/Options";
  15.       
  16.       internal static var _storage:Storage = null;
  17.       
  18.       internal static const PROFILEKEY:String = "GameServicesGroup/CluelessDemo/0.4/Profiles";
  19.       
  20.       internal static const HIGHSCOREKEY:String = "GameServicesGroup/CluelessDemo/0.4/Highscore";
  21.        
  22.       
  23.       public var _scores:Array;
  24.       
  25.       public var Pause:Boolean = false;
  26.       
  27.       internal var _soOptions:SharedObject;
  28.       
  29.       internal var _sCurrentBGM:String = "MenuMusic";
  30.       
  31.       internal var _soHScores:SharedObject;
  32.       
  33.       internal var _stage:Stage;
  34.       
  35.       public function Storage()
  36.       {
  37.          _sCurrentBGM = "MenuMusic";
  38.          Pause = false;
  39.          super();
  40.          _soOptions = SharedObject.getLocal(OPTIONSKEY,"/");
  41.          _soHScores = SharedObject.getLocal(HIGHSCOREKEY,"/");
  42.          initHighScore();
  43.       }
  44.       
  45.       public static function getInstance() : Storage
  46.       {
  47.          if(_storage == null)
  48.          {
  49.             _storage = new Storage();
  50.          }
  51.          return _storage;
  52.       }
  53.       
  54.       public static function clone(param1:Array) : Array
  55.       {
  56.          var _loc2_:Array = null;
  57.          var _loc3_:int = 0;
  58.          _loc2_ = new Array();
  59.          _loc3_ = 0;
  60.          while(_loc3_ < param1.length)
  61.          {
  62.             if(param1[_loc3_] is Array)
  63.             {
  64.                _loc2_.push(clone(param1[_loc3_]));
  65.             }
  66.             else
  67.             {
  68.                _loc2_.push(param1[_loc3_]);
  69.             }
  70.             _loc3_++;
  71.          }
  72.          return _loc2_;
  73.       }
  74.       
  75.       public function get ParticleEffects() : Boolean
  76.       {
  77.          var _loc1_:Boolean = false;
  78.          _loc1_ = true;
  79.          if(_soOptions.data.ParticleEffects != null)
  80.          {
  81.             _loc1_ = Boolean(_soOptions.data.ParticleEffects);
  82.          }
  83.          return _loc1_;
  84.       }
  85.       
  86.       public function set BGMVolume(param1:Number) : void
  87.       {
  88.          _soOptions.data.BGMVolume = param1;
  89.          trace("Set volume " + param1.toString());
  90.          _soOptions.flush();
  91.          applyBGMState();
  92.       }
  93.       
  94.       public function applyFullscreenState() : void
  95.       {
  96.       }
  97.       
  98.       public function set BGMEnabled(param1:Boolean) : void
  99.       {
  100.          _soOptions.data.BGMEnabled = param1;
  101.          _soOptions.flush();
  102.          applyBGMState();
  103.       }
  104.       
  105.       public function set FullscreenEnabled(param1:Boolean) : void
  106.       {
  107.          _soOptions.data.FullscreenEnabled = param1;
  108.          _soOptions.flush();
  109.          applyFullscreenState();
  110.       }
  111.       
  112.       public function resetScores() : void
  113.       {
  114.          var _loc1_:* = undefined;
  115.          for(_loc1_ in _soHScores.data)
  116.          {
  117.             delete _soHScores.data[_loc1_];
  118.          }
  119.          _soHScores.flush();
  120.       }
  121.       
  122.       public function set VoiceOvers(param1:Boolean) : void
  123.       {
  124.          _soOptions.data.VoiceOvers = param1;
  125.          _soOptions.flush();
  126.       }
  127.       
  128.       internal function onFullScreen(param1:FullScreenEvent) : void
  129.       {
  130.          _soOptions.data.FullscreenEnabled = param1.fullScreen;
  131.          _soOptions.flush();
  132.       }
  133.       
  134.       public function saveProfiles() : *
  135.       {
  136.          var _loc1_:SharedObject = null;
  137.          var _loc2_:Array = null;
  138.          var _loc3_:Profile = null;
  139.          _loc1_ = SharedObject.getLocal(PROFILEKEY,"/");
  140.          _loc2_ = new Array();
  141.          for each(_loc3_ in Profile.ProfileList)
  142.          {
  143.             _loc2_.push(_loc3_.save());
  144.          }
  145.          _loc2_.push(Profile.ProfileList.length);
  146.          _loc2_.push(Profile.CurrentProfile.Name);
  147.          _loc1_.data.profiles = _loc2_;
  148.          _loc1_.flush();
  149.          _loc1_.close();
  150.          _loc1_ = null;
  151.       }
  152.       
  153.       public function initHighScore() : void
  154.       {
  155.          var _loc1_:* = undefined;
  156.          _scores = new Array();
  157.          if(_soHScores.size != 0)
  158.          {
  159.             for(_loc1_ in _soHScores.data)
  160.             {
  161.                _scores.push(_soHScores.data[_loc1_]);
  162.             }
  163.             _scores.sortOn("Score",Array.DESCENDING);
  164.          }
  165.       }
  166.       
  167.       public function applySFXState() : void
  168.       {
  169.          MainDocument.DefaultSoundTransform = new SoundTransform(SFXVolume,0);
  170.          SoundManager.getInstance().SFXVolume = SFXVolume;
  171.          if(Pause)
  172.          {
  173.          }
  174.          MainDocument.DefaultSoundTransform = new SoundTransform(0,0);
  175.       }
  176.       
  177.       public function get BGMVolume() : Number
  178.       {
  179.          var _loc1_:Number = NaN;
  180.          _loc1_ = 1;
  181.          if(_soOptions.data.BGMVolume != null)
  182.          {
  183.             _loc1_ = Number(_soOptions.data.BGMVolume);
  184.             trace("Get volume create " + _loc1_.toString());
  185.          }
  186.          trace("Get volume " + _loc1_.toString());
  187.          return _loc1_;
  188.       }
  189.       
  190.       public function get SFXVolume() : Number
  191.       {
  192.          var _loc1_:Number = NaN;
  193.          _loc1_ = 1;
  194.          if(_soOptions.data.SFXVolume != null)
  195.          {
  196.             _loc1_ = Number(_soOptions.data.SFXVolume);
  197.             trace("Get volume create " + _loc1_.toString());
  198.          }
  199.          trace("Get volume " + _loc1_.toString());
  200.          return _loc1_;
  201.       }
  202.       
  203.       public function newProfile(param1:String) : void
  204.       {
  205.          var _loc2_:Profile = null;
  206.          _loc2_ = new Profile();
  207.          _loc2_.Name = param1;
  208.          Profile.CurrentProfile = _loc2_;
  209.          Profile.ProfileList.push(_loc2_);
  210.          saveProfiles();
  211.       }
  212.       
  213.       public function set SFXVolume(param1:Number) : void
  214.       {
  215.          _soOptions.data.SFXVolume = param1;
  216.          trace("Set volume " + param1.toString());
  217.          _soOptions.flush();
  218.          applySFXState();
  219.       }
  220.       
  221.       public function createStartingProfile() : void
  222.       {
  223.          var _loc1_:Profile = null;
  224.          _loc1_ = new Profile();
  225.          _loc1_.Name = "Cher";
  226.          Profile.CurrentProfile = _loc1_;
  227.          Profile.ProfileList = new Array();
  228.          Profile.ProfileList.push(_loc1_);
  229.       }
  230.       
  231.       public function storeHighScore() : void
  232.       {
  233.          var _loc1_:* = undefined;
  234.          var _loc2_:String = null;
  235.          var _loc3_:int = 0;
  236.          _loc3_ = 1;
  237.          if(_scores.length > 0)
  238.          {
  239.             for each(_loc1_ in _scores)
  240.             {
  241.                _loc2_ = "HScore" + _loc3_;
  242.                _soHScores.data[_loc2_] = _loc1_;
  243.                _loc3_++;
  244.                if(_loc3_ > 12)
  245.                {
  246.                   break;
  247.                }
  248.             }
  249.             _soHScores.flush();
  250.          }
  251.       }
  252.       
  253.       public function loadProfiles() : *
  254.       {
  255.          var _loc1_:SharedObject = null;
  256.          var _loc2_:Array = null;
  257.          var _loc3_:String = null;
  258.          var _loc4_:int = 0;
  259.          var _loc5_:Profile = null;
  260.          _loc1_ = SharedObject.getLocal(PROFILEKEY,"/");
  261.          if(typeof _loc1_.data.profiles == "undefined")
  262.          {
  263.             _loc1_.close();
  264.             _loc1_ = null;
  265.             Profile.ProfileList = new Array();
  266.             return;
  267.          }
  268.          _loc2_ = Storage.clone(_loc1_.data.profiles);
  269.          _loc3_ = _loc2_.pop() as String;
  270.          _loc4_ = _loc2_.pop() as int;
  271.          Profile.ProfileList = new Array();
  272.          while(_loc4_ > 0)
  273.          {
  274.             _loc4_--;
  275.             (_loc5_ = new Profile()).load(_loc2_.pop() as Array);
  276.             Profile.ProfileList.push(_loc5_);
  277.          }
  278.          Profile.ProfileList.reverse();
  279.          Profile.CurrentProfile = Profile.getProfile(_loc3_);
  280.          _loc1_.close();
  281.          _loc1_ = null;
  282.       }
  283.       
  284.       public function get VoiceOvers() : Boolean
  285.       {
  286.          var _loc1_:Boolean = false;
  287.          _loc1_ = true;
  288.          if(_soOptions.data.VoiceOvers != null)
  289.          {
  290.             _loc1_ = Boolean(_soOptions.data.VoiceOvers);
  291.          }
  292.          return _loc1_;
  293.       }
  294.       
  295.       public function onActivate(param1:Event) : void
  296.       {
  297.          applyBGMState();
  298.       }
  299.       
  300.       public function onDeactivate(param1:Event) : void
  301.       {
  302.          SoundManager.getInstance().stopBG();
  303.       }
  304.       
  305.       public function playBGM(param1:String) : void
  306.       {
  307.          var musicclass:Class = null;
  308.          var sMusic:String = param1;
  309.          _sCurrentBGM = sMusic;
  310.          trace("Music set to: " + sMusic);
  311.          if(BGMEnabled && _sCurrentBGM != "")
  312.          {
  313.             try
  314.             {
  315.                musicclass = getDefinitionByName(_sCurrentBGM) as Class;
  316.                if(musicclass != null)
  317.                {
  318.                   SoundManager.getInstance().playSoundFromRes(sMusic,new musicclass(),SoundObject.C_BG);
  319.                   SoundManager.getInstance().BGVolume = BGMVolume;
  320.                }
  321.             }
  322.             catch(ex:*)
  323.             {
  324.             }
  325.          }
  326.          else
  327.          {
  328.             SoundManager.getInstance().stopBG();
  329.          }
  330.          if(Pause)
  331.          {
  332.             SoundManager.getInstance().stopBG();
  333.          }
  334.       }
  335.       
  336.       public function get FullscreenEnabled() : Boolean
  337.       {
  338.          var _loc1_:Boolean = false;
  339.          _loc1_ = false;
  340.          if(_soOptions.data.FullscreenEnabled != null)
  341.          {
  342.             _loc1_ = Boolean(_soOptions.data.FullscreenEnabled);
  343.          }
  344.          return _loc1_;
  345.       }
  346.       
  347.       public function applyBGMState() : void
  348.       {
  349.          playBGM(_sCurrentBGM);
  350.       }
  351.       
  352.       public function set ParticleEffects(param1:Boolean) : void
  353.       {
  354.          _soOptions.data.ParticleEffects = param1;
  355.          _soOptions.flush();
  356.       }
  357.       
  358.       public function get BGMEnabled() : Boolean
  359.       {
  360.          var _loc1_:Boolean = false;
  361.          _loc1_ = true;
  362.          if(_soOptions.data.BGMEnabled != null)
  363.          {
  364.             _loc1_ = Boolean(_soOptions.data.BGMEnabled);
  365.          }
  366.          return _loc1_;
  367.       }
  368.       
  369.       public function setStage(param1:Stage) : void
  370.       {
  371.          _stage = param1;
  372.       }
  373.       
  374.       public function deleteProfile(param1:String) : void
  375.       {
  376.          var _loc2_:Array = null;
  377.          var _loc3_:Profile = null;
  378.          _loc2_ = Profile.ProfileList;
  379.          Profile.ProfileList = new Array();
  380.          for each(_loc3_ in _loc2_)
  381.          {
  382.             if(_loc3_.Name != param1)
  383.             {
  384.                Profile.ProfileList.push(_loc3_);
  385.             }
  386.          }
  387.          saveProfiles();
  388.       }
  389.    }
  390. }
  391.